﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using TuanAnhPersonalWeb.Models;

namespace TuanAnhPersonalWeb.Areas.Admin.Controllers
{
    [Authorize(Roles = "admin,images")]
    public class AlbumController : Controller
    {
        private TuanAnhEntities db = new TuanAnhEntities();

        //
        // GET: /Admin/Album/
        
        public ViewResult Index()
        {
            return View(db.TUANANH__ALBUM.ToList());
        }

        //
        // GET: /Admin/Album/Details/5
          
        public ViewResult Details(int id)
        {
            TUANANH__ALBUM tuananh__album = db.TUANANH__ALBUM.Single(t => t.ALBUM_ID == id);
            return View(tuananh__album);
        }

        //
        // GET: /Admin/Album/Create
          
        public ActionResult Create()
        {
            return View();
        } 

        //
        // POST: /Admin/Album/Create
         
        [HttpPost]
        public ActionResult Create(TUANANH__ALBUM tuananh__album)
        {
            if (ModelState.IsValid)
            {
                db.TUANANH__ALBUM.AddObject(tuananh__album);
                db.SaveChanges();
                return RedirectToAction("Index");  
            }

            return View(tuananh__album);
        }
        
        //
        // GET: /Admin/Album/Edit/5
         
        public ActionResult Edit(int id)
        {
            TUANANH__ALBUM tuananh__album = db.TUANANH__ALBUM.Single(t => t.ALBUM_ID == id);
            return View(tuananh__album);
        }

        //
        // POST: /Admin/Album/Edit/5
        
        [HttpPost]
        public ActionResult Edit(TUANANH__ALBUM tuananh__album)
        {
            if (ModelState.IsValid)
            {
                db.TUANANH__ALBUM.Attach(tuananh__album);
                db.ObjectStateManager.ChangeObjectState(tuananh__album, EntityState.Modified);
                db.SaveChanges();
                return RedirectToAction("Index");
            }
            return View(tuananh__album);
        }

        //
        // GET: /Admin/Album/Delete/5
        
        public ActionResult Delete(int id)
        {
            TUANANH__ALBUM tuananh__album = db.TUANANH__ALBUM.Single(t => t.ALBUM_ID == id);
            return View(tuananh__album);
        }

        //
        // POST: /Admin/Album/Delete/5
        
        [HttpPost, ActionName("Delete")]
        public ActionResult DeleteConfirmed(int id)
        {            
            TUANANH__ALBUM tuananh__album = db.TUANANH__ALBUM.Single(t => t.ALBUM_ID == id);
            db.TUANANH__ALBUM.DeleteObject(tuananh__album);
            db.SaveChanges();
            return RedirectToAction("Index");
        }

        protected override void Dispose(bool disposing)
        {
            db.Dispose();
            base.Dispose(disposing);
        }
    }
}